package br.ufmg.vod.collections;

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

import org.apache.commons.collections15.iterators.ArrayIterator;

public class GenericArrayWrapper<T> implements Collection<T>{

	T[] array;
	@Override
	public boolean add(T e) {
		throw new UnsupportedOperationException(); 
	}

	@Override
	public boolean addAll(Collection<? extends T> c) {
		throw new UnsupportedOperationException();
	}

	@Override
	public void clear() {
		throw new UnsupportedOperationException();		
	}

	@Override
	public boolean contains(Object o) {
		return Arrays.binarySearch(array, o) != -1;
	}

	@Override
	public boolean containsAll(Collection<?> c) {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean isEmpty() {
		return array.length == 0;
	}

	@Override
	public Iterator<T> iterator() {
		return new ArrayIterator<T>(array);
	}

	@Override
	public boolean remove(Object o) {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean removeAll(Collection<?> c) {
		throw new UnsupportedOperationException();
	}

	@Override
	public boolean retainAll(Collection<?> c) {
		throw new UnsupportedOperationException();
	}

	@Override
	public int size() {
		return array.length;
	}

	@Override
	public Object[] toArray() {
		return array;
	}

	@SuppressWarnings("hiding")
	@Override
	public <T> T[] toArray(T[] a) {
		System.arraycopy(array, 0, a, 0, array.length);
		return a;
	}
	

}
